package com.example.aopdemo.proxy;



import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-26
 * Time: 19:59
 */
public class Main {
    public static void main(String[] args) {
        /*HouseProxy proxy = new HouseProxy(new RealHouseSubject());
        proxy.rent();
        proxy.sale();*/


        //JDK动态代理
        /*HouseSubject target = new RealHouseSubject();
        *//*HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class}
                ,new JDKInvocation(target));*//*
        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces()
                ,new JDKInvocation(target));
        proxy.rent();
        proxy.sale();*/

        //CGLIB动态对象
        HouseSubject target = new RealHouseSubject();
        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(),new CGLibMethodInterceptor(target));
        proxy.rent();
        proxy.sale();
    }
}
